package com.formiaomiao.demain.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.formiaomiao.demain.R;
import com.formiaomiao.demain.model.FollowUFBean;
import com.formiaomiao.demain.util.UseGlideUtils;

import java.util.List;

public class FollowAdapter extends RecyclerView.Adapter<FollowAdapter.ViewHolder> {

    Context context;
    List<FollowUFBean.DataBean.ListBean> list;

    private onItemClickListener itemClickLisenter;

    public interface onItemClickListener {
        void itemckicklistener(View v, int i);
    }

    public void setOnItemckicklistener(onItemClickListener itemClickLisenter) {
        this.itemClickLisenter = itemClickLisenter;
    }

    public FollowAdapter(Context context, List<FollowUFBean.DataBean.ListBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View v = LayoutInflater.from(context).inflate(R.layout.follow_uf_item, viewGroup, false);
        ViewHolder holder = new ViewHolder(v);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, final int i) {
        UseGlideUtils.setGlide(context, list.get(i).getUserHead(), holder.iv_follow);
        holder.tv_follow.setText(list.get(i).getNickName());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                itemClickLisenter.itemckicklistener(view, i);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        ImageView iv_follow;
        TextView tv_follow;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            iv_follow = itemView.findViewById(R.id.iv_follow);
            tv_follow = itemView.findViewById(R.id.tv_follow);
        }
    }
}
